<?php
//系统接口函数类
namespace core;
defined('BY_JYA') or exit('error');
class core{
	public function checklogin($forward='',$ismemberset=false){
		global $_RQ,$_AR;		
		if($_SESSION['uid']){
			//已登录
			$check=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id','mobile'));			
			if($check['id']){
				return true;
			}		
			unset($_SESSION['uid']);
		}
		//先尝试微信注册
		$setting=uni_setting('register');
		//再次获取一次openid,如果还是失败就算了
		if(!$_SESSION['openid'] && $_SESSION['isauth_basecheck']!=1){
			$_SESSION['isauth_base']=0;
			$_SESSION['isauth_basecheck']=1;
		}
		if($setting['hyzc']==1 || !$_SESSION['openid']){
			//会员注册机制为手动注册，或者未获取到用户openid
			if($_RQ['action']=='module' || get_access_setting(ACCESS_PLUGIN)){
				$_SESSION['forward_url']=$_AR['siteurl'];
				if($_SESSION['os']=='wxapp'){
					exi('','','core/member.login/');
				}else{
					header('Location: '.custom_url('core/member.login/'));
				}
			}else{
				if(!$forward){
					$forward=custom_url($_AR['access_json'],true);
				}
				$_SESSION['forward_url']=$forward;
				if($_SESSION['os']=='wxapp'){
					exi('请先登录！','error','core/member.login/');
				}elseif($_SESSION['os']=='windows'){
					open_modal('core/member.wxauth_code/');
				}else{
					exi('请先登录！','error',custom_url('core/member.login/'));
				}
			}
		}
		$uid=model('core/member')->register();
		return true;
	}
	public function check_setmobile($type=0){
		if($_SESSION['uid'] && $_SESSION['member'] && !$_SESSION['member']['mobile']){
			$register=uni_setting('register');
			if($register['must_mobile']==1 && $register['show_setmobiletype']==$type){
				return true;
			}
		}
		return false;
	}
	public function check_setmember($type=0){
		if($_SESSION['uid'] && $_SESSION['member'] && !$_SESSION['member']['nickname']){
			$register=uni_setting('register');
			if($register['must_member']==1 && $register['show_setmembertype']==$type){
				return true;
			}
		}
		return false;
	}
	  //发放卡券函数
	public function send_card($paramerter){
		$member=cfc('core')->get_member($paramerter['mid']);
		if(!$member){
			return error('会员不存在！');
		}
		//2、检测卡券是否存在，是否还有剩余
		$card=pdo_get('core_card',array('id'=>$paramerter['card_id'],'uniacid'=>$_SESSION['uniacid']),array('num'));
		if(!$card){
			return error('卡券不存在！');
		}
		$used=pdo_count('core_card_log',array('card_id'=>$paramerter['card_id']));
		if($used>=$card['num']){
			return error('卡券已领完！');
		}
		//3、生成 code
		do{
			$code=random(10);
			$check=pdo_getcolumn('core_card_log',array('code'=>$code,'uniacid'=>$_SESSION['uniacid']),'id');
		}while($check);
		//4、发放卡券
		$data=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$paramerter['mid'],
			'card_id'=>$paramerter['card_id'],
			'code'=>$code,
			'status'=>0,
			'createtime'=>TIMESTAMP,
			'plugin'=>$paramerter['form_plugin'],
			'remark'=>$paramerter['remark']
		);
		pdo_insert('core_card_log',$data);
		//5、发送模版消息
		
		//返回
		return true;
	}
	
	//查询单个会员信息
	public function get_member($id,$fields=array()){
		$default_fields=array('id','mobile','username','credit2','credit1','fromuser','createtime','nickname','avatar');
		if($fields){
			$fields=array_intersect($fields,$default_fields);
		}
		$result=pdo_get('core_members',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']),$fields);
		return $result;
	}
	//获取粉丝信息
	public function get_fans($openidmid){
		if(!$openidmid){
			return array();
		}
		if (is_numeric($openidmid)) {
			$fans = pdo_get('core_fans', array('mid' => $openidmid));
		} else {
			$fans = pdo_get('core_fans', array('openid' => $openidmid));
		}
		if ($fans) {
			$fans['uid'] = $fans['mid'];
		}
		return $fans;
	}
	//修改积分余额
	
	public function member_credit($mid,$field,$value,$is_add,$from_plugin,$remark='',$tag='',$op_mid=0){
		return model('core/member')->member_credit($mid,$field,$value,$is_add,$from_plugin,$remark,$tag,$op_mid);
	}
	public function member_show($mid,$default_url='',$default=false){
		return model('core/member')->member_show($mid,$default_url,$default);
	}
	//发起支付
	public function pay($parameter){
		global $_RQ;
		//$parameter['no_type']=$parameter['no_type']?$parameter['no_type']:array();
		do{
			$tid='JYA'.TIMESTAMP.random(7);
			$old=pdo_getcolumn('core_paylog',array('tid'=>$tid),'id');
		}while($old);
		if(is_array($parameter['back_url'])){
			$parameter['back_url']=ijson_encode($parameter['back_url']);
		}
		$data=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'tid'=>$tid,
			'oid'=>$parameter['id'],
			'status'=>0,
			'createtime'=>TIMESTAMP,
			'title'=>$parameter['title']?$parameter['title']:'支付订单',
			'no_type'=>$parameter['no_type']?ijson_encode($parameter['no_type']):'',
			'fee'=>$parameter['fee'],
			'plugin'=>$parameter['plugin'],
			'action'=>$parameter['action'],
			'more'=>$parameter['more']?$parameter['more']:'',
			'back_url'=>$parameter['back_url'],
		);
		pdo_insert('core_paylog',$data);
		$id=pdo_insertid();
		$return['id']=$id;
		if($_SESSION['os'] == 'wxapp') {
			exi($return);
		}else{
			if($_RQ['action']=='module'){
				header('Location: '.custom_url('core/pay//id='.$id));
			}else{
				$pay_action=array('plugin'=>'core','action'=>'pay','query'=>'id='.$id);
				exi('正在跳转支付页','',$pay_action);
			}
		}
		
	}
	public function account_pay($parameter){
		global $_RQ;
		do{
			$ordersn='JYA'.TIMESTAMP.random(7);
			$old=pdo_getcolumn('core_account_pay_log',array('ordersn'=>$ordersn),'id');
		}while($old);
		if(!$parameter['back_url']){
			return error('请先设置回调地址');
		}
		$data=array(
			'uniacid'=>$_SESSION['uniacid'],
			'ordersn'=>$ordersn,
			'order_id'=>$parameter['id'],
			'status'=>0,
			'createtime'=>TIMESTAMP,
			'title'=>$parameter['title']?$parameter['title']:'支付订单',
			'no_type'=>$parameter['no_type']?ijson_encode($parameter['no_type']):'',
			'fee'=>$parameter['fee'],
			'remark'=>$parameter['remark']?$parameter['remark']:'',
			'back_url'=>$parameter['back_url'],
		);
		pdo_insert('core_account_pay_log',$data);
		$id=pdo_insertid();
		return $id;
	}
	public function plugin($plugin_name){
		//调用插件对外接口
		static $plugins=array();
		if(!$plugins[$plugin_name]){
			$class='func_'.$plugin_name;
			//判断是否已声明过该类，防止重复加载
			if(!class_exists($class)){
				$file=ROOT_PLUGIN.$plugin_name.'/func.php';
				if(!is_file($file)){
					return error('no class');
				}
				require $file;
			}
			$plugins[$plugin_name]=new $class($plugin_name);
		}
		return $plugins[$plugin_name];
	}
	//短信接口函数
	public function sendsms($mobile,$content,$mid='',$pluginname=''){
		//短信接口，根据系统设置调用相关插件短信接口，设置时只设置插件名，插件方法由系统默认： sendsms($mobile,$content)
		//系统级的短信接口，为统一短信调用接口。设两个层次的短信设置，全站统一设置和每个用户独立设置
		if(!$mobile || !$content){
			return error('参数错误！请先设置短息发送号码和发送内容！');
		}
		if($_SESSION['this']=='manage'){
			$setting=core_setting('sms');
		}else{
			$setting=uni_setting('sms');
		}
		//$setting=core_setting('sms');
		//if(!$setting['all_sys']){
			//调用用户短信接口
			if($setting['plugin']){
				$result=$this->plugin($setting['plugin'])->sendsms($mobile,$content,$mid,$pluginname);
				if(!$result && $setting['plugin1']){
					$result=$this->plugin($setting['plugin1'])->sendsms($mobile,$content,$mid,$pluginname);
				}
				return $result;
			}
			exi('站点短信接口设置异常，无法发送短信，请来信网站管理员！','error');
	}
	
	public function getalipay($data,$alipay_config=array()){
		global $_AR;
		$default=array(
			'sign_type'=>'MD5',
			'input_charset'=>'utf-8',
			'cacert'=>ROOT_D.'/core/library/alipay/cacert.pem',
			'transport'=>'http'
		);
		if(!$alipay_config){
			$config=core_setting('pay');
			$alipay_config=array('partner'=>$config['alipay_partner'],'seller_email'=>$config['alipay_seller_email'],'key'=>$config['alipay_key']);
		}
		$alipay_config=array_merge($default,$alipay_config);
		$total_fee=$data['total_fee'];
		$parameter = array(
			"service" => "create_direct_pay_by_user",
			"partner" => trim($alipay_config['partner']),
			"payment_type"	=> "1",
			"notify_url"	=>$data['notify_url'],
			"return_url"	=> $data['return_url'],
			"seller_email"	=> $alipay_config['seller_email'],
			"out_trade_no"	=> $data['out_trade_no'],
			"subject"	=> $data['subject'],
			"total_fee"	=> $total_fee,
			"extra_common_param"=>urlencode('auser.payresult'),
			"_input_charset"	=> trim(strtolower($alipay_config['input_charset']))
		);
		require ROOT_D.'/core/library/alipay/lib/alipay_submit.class.php';
		$alipaySubmit = new \AlipaySubmit($alipay_config);
		$html_text = $alipaySubmit->buildRequestForm($parameter,"get", "确认");
		return $html_text;
	}
	public function get_back($key,$plugin_name) {
		$cover=pdo_get('core_back',array('uniacid'=>$_SESSION['uniacid'],'plugin'=>$plugin_name,'key'=>$key));
       	if($cover){
			$cover['content']=json_decode($cover['content'],true);
			$return=array(
				'keytype'=>$cover['keytype'],
				'keyword'=>$cover['keyword'],
				'status'=>$cover['status'],
				'backtype'=>$cover['backtype'],
				'key'=>$cover['key'],
				'title'=>$cover['content']['0']['title'],
				'picurl'=>$cover['content']['0']['picurl'],
				'description'=>$cover['content']['0']['description'],
				'url'=>$cover['content']['0']['url']
			);
		}else{
			$return=array();
		}
		return $return;
	}
	public function get_back_newss($parameter,$id='') {
		if($id){
			$back=pdo_get('core_back',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}elseif($parameter['key']){
			$back=pdo_get('core_back',array('uniacid'=>$_SESSION['uniacid'],'key'=>$parameter['key']));
		}elseif($parameter['aid'] || $parameter['id']){
			$keyid=$parameter['id']?:$parameter['aid'];
			$back=pdo_get('core_back',array('uniacid'=>$_SESSION['uniacid'],'key'=>$parameter['action'].$keyid));
		}else{
			$back=pdo_get('core_back',array('uniacid'=>$_SESSION['uniacid'],'plugin'=>$parameter['plugin'],'key'=>$parameter['action']));
		}
		if($back){
			$back['content']=json_decode($back['content'],true);
			$return=array(
				'status'=>$back['status'],
				'title'=>$back['content']['0']['title'],
				'picurl'=>$back['content']['0']['picurl'],
				'description'=>$back['content']['0']['description'],
				'url'=>$back['content']['0']['url']
			);
			$return['keywords']=pdo_getall('core_back_keyword',array('back_id'=>$back['id'],'uniacid'=>$_SESSION['uniacid']),array('id','type','keyword'));
		}else{
			$return=array();
		}
		return $return;
	}
	public function keywords($name='keywords'){
		return array(
			'type'=>'array',
			'title'=>'关键词',
			'tip'=>'关键词列表：</br>
			精确匹配：当粉丝输入的内容和本回复规则的关键词一致时触发回复；</br>
			模糊匹配：当粉丝输入的内容包含本回复规则的关键词时触发回复；</br>
			正则匹配：使用MySQL的匹配引擎，请使用MySQL的正则语法。</br>
			正则匹配示例: ^微信匹配以“微信”开头的语句；微信$匹配以“微信”结尾的语句；^微信$匹配等同“微信”的语句；微信匹配包含“微信”的语句；[0-9.-]匹配所有的数字，句号和减号；^[a-zA-Z_]$所有的字母和下划线；^[[:alpha:]]{3}$所有的3个字母的单词；^a{4}$aaaa；^a{2,4}$aa，aaa或aaaa；^a{2,}$匹配多于两个a的字符串。',
			'name'=>$name,
			'add_tip'=>'添加一个关键词',
			'list'=>array(
				array('type'=>'string','name'=>'keyword','title'=>'关键词内容'),
				array('type'=>'radio','name'=>'type','title'=>'关键词类型','options'=>'keytypes'),
			),'details'=>array(
				array('type'=>'radio','name'=>'type','title'=>'关键词类型','options'=>'keytypes','help'=>''),
				array('type'=>'string','name'=>'keyword','title'=>'关键词内容','help'=>''),
			)
		);
	}
	//保存图文回复
	public function save_back_news($parameter,$id='') {
		//参数说明： $parameter=array('keywords'=>'触发关键词数组','status'=>'是否启用','title'=>'封面标题','description'=>'封面简介','picurl'=>'封面图片地址','url'=>'图文链接','action'=>'链接页面action','id'=>'链接页面ID（可不填）');
		//参数说明： $id:回复规则ID，用于更新回复规则
		global $_AR;
		$post=array(
			'backtype'=>2,
			'action'=>$parameter['action'],
			'plugin'=>$parameter['plugin'],
			'key'=>$parameter['key']?:$parameter['action'].$parameter['id'],
			'title'=>$parameter['title'],
		);
		if(isset($parameter['status'])){
			$post['status']=$parameter['status'];
		}else{
			$post['status']=1;
		}
		if($parameter['url']){
			$url=$parameter['url'];
		}else{
			$url='./index.php?i='.$_SESSION['uniacid'].'&plugin='.$parameter['plugin'].'&action='.$parameter['action'];
			if($parameter['id']){
				$url.='&id='.$parameter['id'];
			}
		}
		//exi($url,'error');
		$content=array('0'=>array('title'=>$parameter['title'],'description'=>$parameter['description'],'picurl'=>$parameter['picurl'],'url'=>$url ));
		$post['content']=ijson_encode($content);
		if($id){
			pdo_update('core_back',$post,array('id'=>$id));
		}else{
			if($parameter['key']){
				$id=pdo_getcolumn('core_back',array('uniacid'=>$_SESSION['uniacid'],'key'=>$parameter['key']),'id');
			}elseif($parameter['aid'] || $parameter['id']){
				$keyid=$parameter['id']?:$parameter['aid'];
				$id=pdo_getcolumn('core_back',array('uniacid'=>$_SESSION['uniacid'],'key'=>$parameter['action'].$keyid),'id');
			}else{
				$id=pdo_getcolumn('core_back',array('uniacid'=>$_SESSION['uniacid'],'plugin'=>$parameter['plugin'],'key'=>$parameter['action']),'id');
			}
			if($id){
				pdo_update('core_back',$post,array('id'=>$id));
			}else{
				$post['uniacid']=$_SESSION['uniacid'];
				$post['createtime']=TIMESTAMP;
				pdo_insert('core_back',$post);
				$id=pdo_insertid();
			}
		}
		//整理保存关键词
		if($parameter['keyword']){
			//单关键词模式
			$data=array('type'=>1,'keyword'=>$parameter['keyword']);
			$check=pdo_getcolumn('core_back_keyword',array('back_id'=>$id),'id');
			if($check){
				pdo_update('core_back_keyword',$data,array('id'=>$check));
			}else{
				$data['back_id']=$id;
				$data['uniacid']=$_SESSION['uniacid'];
				pdo_insert('core_back_keyword',$data);
			}
		}elseif($parameter['keywords']){
			//多关键词模式
			$old=pdo_getall('core_back_keyword',array('back_id'=>$id),array('id'),'id');
			$old=array_keys($old);
			$ids=array();
			foreach($parameter['keywords'] as &$keyword){
				$data=array(
					'type'=>intval($keyword['type']),
					'keyword'=>$keyword['keyword'],
				);
				if($keyword['id']){
					$ids[]=$keyword['id'];
					pdo_update('core_back_keyword',$data,array('id'=>intval($keyword['id']),'uniacid'=>$_SESSION['uniacid']));
				}else{
					$data['uniacid']=$_SESSION['uniacid'];
					$data['back_id']=$id;
					pdo_insert('core_back_keyword',$data);
				}
			}
			foreach($old as $row){
				if(!in_array($row,$ids)){
					pdo_delete('core_back_keyword',array('id'=>$row));
				}
			}
		}else{
			exi('请先设置关键词！','error');
		}
		return $id;
	}
	public function get_back_news($parameter,$id='') {
		if($id){
			$cover=pdo_get('core_back',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}elseif($parameter['key']){
			$cover=pdo_get('core_back',array('uniacid'=>$_SESSION['uniacid'],'key'=>$parameter['key']));
		}elseif($parameter['aid'] || $parameter['id']){
			$keyid=$parameter['id']?:$parameter['aid'];
			$cover=pdo_get('core_back',array('uniacid'=>$_SESSION['uniacid'],'key'=>$parameter['action'].$keyid));
		}else{
			$cover=pdo_get('core_back',array('uniacid'=>$_SESSION['uniacid'],'plugin'=>$parameter['plugin'],'key'=>$parameter['action']));
		}
		if($cover){
			$cover['content']=json_decode($cover['content'],true);
		}
		$return=array(
			'status'=>$cover['status'],
			'backtype'=>$cover['backtype'],
			'key'=>$cover['key'],
			'title'=>$cover['content']['0']['title'],
			'picurl'=>$cover['content']['0']['picurl'],
			'description'=>$cover['content']['0']['description'],
			'url'=>$cover['content']['0']['url']
		);
		$return['keyword']=pdo_getcolumn('core_back_keyword',array('back_id'=>$cover['id']),'keyword');
		return $return;
	}
	
	public function save_back($data,$plugin_name='core',$id=0) {
		$post=array(
			'backtype'=>$data['backtype']?intval($data['backtype']):2,
			'paixu'=>intval($data['paixu']),
			'status'=>intval($data['status']),
			'key'=>$data['key'],
			'title'=>$data['title']
		);
		//文本回复
		if($post['backtype']==1){
			$post['content']=json_encode(array('content'=>$data['content']));
		}
		//单图文回复
		if($post['backtype']==2){
			$post['content']=json_encode(array('0'=>array('title'=>$data['title'],'description'=>$data['description'],'picurl'=>$data['picurl'],'url'=>$data['url'])));
		}
		//图片回复
		if($post['backtype']==3){
			$post['content']=json_encode(array('url'=>$data['url']));
		}
		//语音回复
		if($post['backtype']==4){
			$post['content']=json_encode(array('url'=>$data['url']));
		}
		//视频回复
		if($data['backtype']==5){
			$post['content']=json_encode(array('url'=>$data['url'],'title'=>$data['title'],'description'=>$data['description']));
		}
		//音乐回复
		if($post['backtype']==6){
			$post['content']=json_encode(array('url'=>$data['url'],'title'=>$data['title'],'description'=>$data['description']));
		}
		//卡券回复
		if($post['backtype']==7){
			$post['content']=json_encode(array('card_id'=>$data['card_id']));
		}
		//事件回复
		if($post['backtype']==8){
			$post['content']=json_encode(array('event'=>$data['event'],'other'=>$data['other']));
		}
		if($id){
			pdo_update('core_back',$post,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		}else{
			$id=pdo_getcolumn('core_back',array('uniacid'=>$_SESSION['uniacid'],'key'=>$data['key']),'id');
			if($id){
				pdo_update('core_back',$post,array('id'=>$id));
			}else{
				$post['uniacid']=$_SESSION['uniacid'];
				$post['plugin']=$plugin_name;
				$post['createtime']=TIMESTAMP;
				pdo_insert('core_back',$post);
				$id=pdo_insertid();
			}
		}
		$update=array(
			'type'=>$data['keytype']?intval($data['keytype']):1,
			'keyword'=>$data['keyword'],
		);
		if(pdo_getcolumn('core_back_keyword',array('back_id'=>$id),'id')){
			pdo_update('core_back_keyword',$update,array('back_id'=>$id));
		}else{
			$update['uniacid']=$_SESSION['uniacid'];
			$update['back_id']=$id;
			pdo_insert('core_back_keyword',$update);
		}
		return $id;
	}
	public function del_back($id){
		$id=intval($id);
		if(!$id){
			return error('参数需为数字');
		}
		pdo_delete('core_back',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		pdo_delete('core_back_keyword',array('back_id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		return true;
	}
	public function setkefu($message,$back) {
		$senddata['touser'] = $message['FromUserName'];
		$senddata['msgtype'] = 'text';
		if(!empty($message['FromUserName'])){
			$openid = $message['FromUserName'];
		}else{
			$text = '认证服务号才能使用微信客服哦！';
			$senddata['text']['content'] = $text;
			$res = cfc('account')->sendCustomNotice($senddata);
			return null;
		}
		$kf_account = $back['content']['other']['kf_account'];
		$welcometext= $back['content']['other']['welcometext'];
		$content = cfc('kefu')->setkfsession($kf_account,$openid);
		if($content['errcode'] != 0){
			$text = cfc('kefu')->error_code($content['errcode']);
			$senddata['text']['content'] = $text;
			$res = cfc('account')->sendCustomNotice($senddata);
			return null;
		}
		$text = $welcometext?: '您好！有任何问题，请直接发信息咨询！';
		$senddata['text']['content'] = $text;
		$senddata['customservice']=$kf_account;
		$res = cfc('account')->sendCustomNotice($senddata);
		return null;
	}
	public function get_template_title(){
		return array(
			'string'=>array('id'=>'string','title'=>'字符串'),
			'copy'=>array('id'=>'copy','title'=>'复制'),
			'switch'=>array('id'=>'switch','title'=>'开关'),
			'audio'=>array('id'=>'audio','title'=>'音频'),
			'checkbox'=>array('id'=>'checkbox','title'=>'多选'),
			'color'=>array('id'=>'color','title'=>'颜色选择'),
			'colorpicker'=>array('id'=>'colorpicker','title'=>'颜色选择2'),
			'day'=>array('id'=>'day','title'=>'日期选择'),
			'icon'=>array('id'=>'icon','title'=>'图标选择'),
			'image'=>array('id'=>'image','title'=>'单图'),
			'images'=>array('id'=>'images','title'=>'多图'),
			'lat_lng'=>array('id'=>'lat_lng','title'=>'经纬度'),
			'link'=>array('id'=>'link','title'=>'链接'),
			'password'=>array('id'=>'password','title'=>'密码'),
			'pcd'=>array('id'=>'pcd','title'=>'行政区划'),
			'radio'=>array('id'=>'radio','title'=>'单选'),
			'select'=>array('id'=>'select','title'=>'列表选择'),
			'text'=>array('id'=>'text','title'=>'文本'),
			'richtext'=>array('id'=>'richtext','title'=>'富文本'),
			'time'=>array('id'=>'time','title'=>'时间选择'),
			'time_range'=>array('id'=>'time_range','title'=>'时间段选择'),
			'video'=>array('id'=>'video','title'=>'视频'),
			'array'=>array('id'=>'array','title'=>'数组'),
			'specs'=>array('id'=>'specs','title'=>'商品规格'),
			'slider'=>array('id'=>'slider','title'=>'滑块'),
			'hdps'=>array('id'=>'hdps','title'=>'幻灯片'),
		);
	}
	public function plugin_exists($plugin_name){
		$plugin=pdo_getcolumn('core_plugins',array('name'=>$plugin_name),'id');
		return $plugin?true:false;
	}
	public function xiu_cloud_request($action,$post=array()){
		global $_AR;
		$cloud=core_setting('cloud');
		if(!$cloud){
			exi('请先注册云服务！','error');
		}
		$post['cloudkey']=$cloud['cloudkey'];
		$post['uniacid']=$_SESSION['uniacid'];
		$post['action']=$action;
		$cloud_url='http://xiu.jinyunweb.com/';
		$bak=cfc('http')->ihttp_request($cloud_url.'api.php',$post);
		$result=@unserialize(base64_decode($bak['content']));
		if(is_array($result)){
			if($result['type']=='error'){
				exi($result['message'],'error');
			}elseif($result['type']=='success'){
				return $result['message'];
			}
			exi('连接云服务失败','error');
		}
		exi('云服务没有反馈数据','error');
	}
}